#include <iostream>
#include <set>
#include <vector>
using std::cout;
using std::endl;
using namespace std;

vector<int> combination(){
    int n, m;
    cin >> n >> m;
    
    vector<int> A(n), B(m);
    for (int i = 0; i < n; ++i) cin >> A[i];
    for (int i = 0; i < m; ++i) cin >> B[i];

    vector<int> res;
    int i = 0, j = 0;
    while (i < n && j < m) {
        if (A[i] < B[j]) res.push_back(A[i++]);
        else if (A[i] > B[j]) res.push_back(B[j++]);
        else { res.push_back(A[i]); i++; j++; }  // 去重
    }
    while (i < n) res.push_back(A[i++]);
    while (j < m) res.push_back(B[j++]);

    return res;
}

int main()
{
    vector<int> result = combination();
    
    for(auto& num : result){
        cout << num << " ";
    }

    return 0;
}

